Hide And Show Check Box
Complete Code For Hide And Show Check Box In Flutter
main.dart
import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.red, ), home: MyHomePage(), ); } } class MyHomePage extends StatefulWidget { @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { bool _isCheckBoxVisible = true; bool _isChecked = true; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Colors.lightGreen[900], title: Text("Hide And Show CheckBox"), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.max, children: <Widget>[ _isCheckBoxVisible ? CheckboxListTile( value: _isChecked, onChanged: (val) => setState(() => _isChecked = val), title: Text("Check Box Text"), ) : SizedBox(), SizedBox(height: 30.0), RaisedButton( color: Colors.lightGreen[900], textColor: Colors.white, child: Text(_isCheckBoxVisible ? "Hide" : "Show"), onPressed: () { setState(() => _isCheckBoxVisible = !_isCheckBoxVisible); }, ), ], ), ), ); } }